﻿Imports System
Imports System.Data
Imports System.Windows.Forms
Imports MySql.Data.MySqlClient

Public Class yuangongchaxun
    Dim conn As MySqlConnection
    Dim memoryImage As Bitmap

    '退出
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.Close()
        mainview.Enabled = True
        mainview.Focus
    End Sub

    '查询所有
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim connstr As String
        Dim data As DataTable
        Dim da As MySqlDataAdapter
        Dim cb As MySqlCommandBuilder

        connstr = My.Settings.MysqlDB
        conn = New MySqlConnection(connstr)

        data = New DataTable

        da = New MySqlDataAdapter("SELECT * FROM zgb", conn)
        cb = New MySqlCommandBuilder(da)

        da.Fill(data)
        DataGridView1.DataSource = data
    End Sub

    '卡号查询详细
    Private Sub Kahao_detail(p1 As Integer)
        Dim connstr As String
        Dim data As DataTable
        Dim da As MySqlDataAdapter
        Dim cb As MySqlCommandBuilder
        Dim comm As String
        Dim sex As Boolean

        connstr = My.Settings.MysqlDB
        conn = New MySqlConnection(connstr)

        comm = String.Format("SELECT * FROM zgb WHERE card_num='{0}'", p1)

        da = New MySqlDataAdapter(comm, conn)
        cb = New MySqlCommandBuilder(da)
        data = New DataTable
        da.Fill(data)

        Me.DataGridView2.DataSource = data

        Me.DataGridView2.CurrentCell = Me.DataGridView2(1, 0)
        yuangong_detail.workid.Text = Me.DataGridView2.CurrentCell.Value.ToString

        Me.DataGridView2.CurrentCell = Me.DataGridView2(1 + Me.DataGridView2.CurrentCellAddress.X, 0)
        yuangong_detail.name_worker.Text = Me.DataGridView2.CurrentCell.Value.ToString

        Me.DataGridView2.CurrentCell = Me.DataGridView2(1 + Me.DataGridView2.CurrentCellAddress.X, 0)
        yuangong_detail.IDnum.Text = Me.DataGridView2.CurrentCell.Value.ToString

        Me.DataGridView2.CurrentCell = Me.DataGridView2(1 + Me.DataGridView2.CurrentCellAddress.X, 0)
        sex = Me.DataGridView2.CurrentCell.Value
        If (sex) Then
            'sex=1,女
            yuangong_detail.SEXComboBox1.SelectedIndex = 1
        Else
            'sex=0，男
            yuangong_detail.SEXComboBox1.SelectedIndex = 0
        End If

        Me.DataGridView2.CurrentCell = Me.DataGridView2(1 + Me.DataGridView2.CurrentCellAddress.X, 0)
        yuangong_detail.age.Text = Me.DataGridView2.CurrentCell.Value.ToString

        Me.DataGridView2.CurrentCell = Me.DataGridView2(1 + Me.DataGridView2.CurrentCellAddress.X, 0)
        yuangong_detail.telephone.Text = Me.DataGridView2.CurrentCell.Value.ToString

        yuangong_detail.Show()
    End Sub

    '工号查询详细
    Private Sub Gonghao_detail(p1 As Integer)
        Dim connstr As String
        Dim data As DataTable
        Dim da As MySqlDataAdapter
        Dim cb As MySqlCommandBuilder
        Dim comm As String

        connstr = My.Settings.MysqlDB
        conn = New MySqlConnection(connstr)

        comm = String.Format("SELECT * FROM zgb WHERE work_id='{0}'", p1)

        da = New MySqlDataAdapter(comm, conn)
        cb = New MySqlCommandBuilder(da)
        data = New DataTable
        da.Fill(data)

        Me.DataGridView2.DataSource = data

        Me.DataGridView2.CurrentCell = Me.DataGridView2(1, 0)
        yuangong_detail.workid.Text = Me.DataGridView2.CurrentCell.Value.ToString

        Me.DataGridView2.CurrentCell = Me.DataGridView2(1 + Me.DataGridView2.CurrentCellAddress.X, 0)
        yuangong_detail.name_worker.Text = Me.DataGridView2.CurrentCell.Value.ToString

        Me.DataGridView2.CurrentCell = Me.DataGridView2(1 + Me.DataGridView2.CurrentCellAddress.X, 0)
        yuangong_detail.IDnum.Text = Me.DataGridView2.CurrentCell.Value.ToString

        Me.DataGridView2.CurrentCell = Me.DataGridView2(1 + Me.DataGridView2.CurrentCellAddress.X, 0)
        'yuangong_detail.SEXComboBox1.Text = Me.DataGridView2.CurrentCell.Value

        Me.DataGridView2.CurrentCell = Me.DataGridView2(1 + Me.DataGridView2.CurrentCellAddress.X, 0)
        yuangong_detail.age.Text = Me.DataGridView2.CurrentCell.Value.ToString

        Me.DataGridView2.CurrentCell = Me.DataGridView2(1 + Me.DataGridView2.CurrentCellAddress.X, 0)
        yuangong_detail.telephone.Text = Me.DataGridView2.CurrentCell.Value.ToString

        yuangong_detail.Show()
    End Sub

    '卡号查询
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click

        Kahao_detail(CInt(InputBox("请输入卡号或刷卡", "卡号查询")))
        '需要处理空值错误
    End Sub

    '工号查询
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        Gonghao_detail(CInt(InputBox("请输入员工工号", "工号查询")))
        '需要处理空值错误
    End Sub

    Private Sub yuangongchaxun_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim connstr As String
        Dim data As DataTable
        Dim da As MySqlDataAdapter
        Dim cb As MySqlCommandBuilder
        connstr = My.Settings.MysqlDB
        conn = New MySqlConnection(connstr)

        data = New DataTable

        da = New MySqlDataAdapter("SELECT * FROM zgb", conn)
        cb = New MySqlCommandBuilder(da)

        da.Fill(data)
        DataGridView1.DataSource = data
    End Sub


End Class